#!/usr/bin/env python3
"""
审计日志相关Pydantic模式
"""

from datetime import datetime
from typing import Any

from pydantic import BaseModel, Field


class AuditLogBase(BaseModel):
    """审计日志基础模式"""

    operator: str = Field(..., max_length=100, description="操作人")
    operation_type: str = Field(..., max_length=50, description="操作类型")
    operation_target: str = Field(..., max_length=100, description="操作目标")
    operation_details: dict[str, Any] | None = Field(None, description="操作详情")
    ip_address: str | None = Field(None, max_length=45, description="IP地址")
    user_agent: str | None = Field(None, max_length=500, description="用户代理")
    success: bool = Field(True, description="操作是否成功")
    error_message: str | None = Field(None, description="错误信息")
    related_visitor_id: int | None = Field(None, description="关联访客ID")
    related_qrcode: str | None = Field(None, max_length=500, description="关联二维码")


class AuditLogResponse(AuditLogBase):
    """审计日志响应模式"""

    id: int
    operation_time: datetime

    class Config:
        from_attributes = True


class AuditLogListResponse(BaseModel):
    """审计日志列表响应模式"""

    data: list[AuditLogResponse]
    total: int
    page: int
    page_size: int
    total_pages: int
